/**
 * 
 */
package unitTests;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.Before;

import datamodels.Conference;
import datamodels.Manuscript;
import datamodels.Role;
import datamodels.User;


/**
 * Performs JUnit testing on Conference class. 
 * 
 * @author Alan Meaker
 * @version 11.17.2011
 */
public class ConferenceTest
{
	//test conference
	protected Conference con;
	
	//test users
	protected User	a0,
				  	a1,
				  	a2,
				  	a3;
	
	//test manuscripts
	protected Manuscript	man0,
							man1,
							man2,
							man3,
							man4,
							man5,
							man6,
							man7,
							man8,
							man9;
	
	//list to contain manuscripts for addition to conference
	protected List<Manuscript> man_list;

	@Before
	public void setUp()
	{
	  //initialize conference
	  con = new Conference();
	  
	  //initialize all users and set their role as author
	  a0 = new User("Alan");
	  a0.setCurrentRole(Role.AUTHOR);
	  a1 = new User("Anthony");
	  a1.setCurrentRole(Role.AUTHOR);
	  a2 = new User("Rithy");
	  a2.setCurrentRole(Role.AUTHOR);
	  a3 = new User("Zach");
	  a3.setCurrentRole(Role.AUTHOR);
	  
	  //initialize list of manuscripts
	  man_list = new ArrayList<Manuscript>();
	  
	  //initialize all manuscripts
	  man0 = new Manuscript();
	  man1 = new Manuscript();
	  man2 = new Manuscript();
	  man3 = new Manuscript();
	  man4 = new Manuscript();
	  man5 = new Manuscript();
	  man6 = new Manuscript();
	  man7 = new Manuscript();
	  man8 = new Manuscript();
	  man9 = new Manuscript();
	  
	  //assign authors to the manuscripts
	  //a0 - man0,man3,man4,man7,man8,man9 = 6
	  //a1 - man1,man5 = 2
	  //a2 - man2 = 1
	  //a3 - = 0
	  man0.setAuthor(a0);
	  man1.setAuthor(a1);
	  man2.setAuthor(a2);
	  man3.setAuthor(a0);
	  man4.setAuthor(a0);
	  man5.setAuthor(a1);
	  man6.setAuthor(a0);
	  man7.setAuthor(a0);
	  man8.setAuthor(a0);
	  man9.setAuthor(a0);
	  
	  //add all the manuscripts to the manuscript list
	  man_list.add(man0);
	  man_list.add(man1);
	  man_list.add(man2);
	  man_list.add(man3);
	  man_list.add(man4);
	  man_list.add(man5);
	  man_list.add(man6);
	  man_list.add(man7);
	  man_list.add(man8);
	  man_list.add(man9);
	  
	  //set man_list as the list of all manuscripts in the conference
	  con.setManList(man_list);
	}
	
	/**
	 * Tests the getManuscripts() method in regards to returning manuscripts
	 * from an author that submitted multiple manuscripts to the conference. 
	 * 
	 * @author Alan Meaker
	 * @version 11.17.2011
	 * 
	 * 
	 * @post	The call to getManuscripts(a0) will return a list of all
	 * 			manuscripts that user a0 wrote.
	 */
	@Test
	public void testGetManuscriptsA0()
	{
		//create list of all manuscripts by a0
		List<Manuscript> a0Manuscripts = new ArrayList<Manuscript>();
		a0Manuscripts.add(man0);
		a0Manuscripts.add(man3);
		a0Manuscripts.add(man4);
		a0Manuscripts.add(man7);
		a0Manuscripts.add(man8);
		a0Manuscripts.add(man9);
		
		//assert that all manuscripts returned are by a0
		//and all manuscripts by a0 are returned
		assertTrue("Error getting a0's manuscripts",
				   con.getManuscriptsByAuthor(a0).containsAll(a0Manuscripts));
		
	}
	
	/**
	 * Tests the getManuscripts() method in regards to returning manuscripts
	 * from an author that submitted multiple, non-sequential, manuscripts to
	 * the conference. 
	 * 
	 * @author Alan Meaker
	 * @version 11.17.2011
	 * 
	 * 
	 * @post	The call to getManuscripts(a1) will return a list of all
	 * 			manuscripts that user a1 wrote.
	 */
	@Test
	public void testGetManuscriptsA1()
	{
		//create list of all manuscripts by a1
		List<Manuscript> a1Manuscripts = new ArrayList<Manuscript>();
		a1Manuscripts.add(man1);
			
		//assert that all manuscripts returned are by a1
		//and all manuscripts by a1 are returned
		assertTrue("Error getting a1's manuscripts",
				   con.getManuscriptsByAuthor(a1).containsAll(a1Manuscripts));
	}
	
	/**
	 * Tests the getManuscripts() method in regards to returning manuscripts
	 * from an author that submitted a single manuscript to the conference. 
	 * 
	 * @author Alan Meaker
	 * @version 11.17.2011
	 * 
	 * 
	 * @post	The call to getManuscripts(a2) will return a list containing the
	 * 			sole manuscript that user a2 wrote.
	 */
	@Test
	public void testGetManuscriptsA2()
	{
		//create list of all manuscripts by a2
		List<Manuscript> a2Manuscripts = new ArrayList<Manuscript>();
		a2Manuscripts.add(man2);
			
		//assert that all manuscripts returned are by a2
		//and all manuscripts by a2 are returned
		assertTrue("Error getting a2's manuscripts",
				   con.getManuscriptsByAuthor(a2).containsAll(a2Manuscripts));
	}
	
	/**
	 * Tests the getManuscripts() method in regards to returning manuscripts
	 * from an author that has not submitted any manuscripts to the conference. 
	 * 
	 * @author Alan Meaker
	 * @version 11.17.2011
	 * 
	 * 
	 * @post	The call to getManuscripts(a3) will return an empty list showing
	 * 			that user a3 has 0 manuscripts in the conference.
	 */
	@Test
	public void testGetManuscriptsA3()
	{		
		//assert that all manuscripts returned are by a2
		//and all manuscripts by a2 are returned
		assertTrue("Error getting a3's manuscripts",
				   con.getManuscriptsByAuthor(a3).isEmpty());
	}

}